//
//  WCNAddCareRecordSheetsPopView.m
//  WCN
//
//  Created by 杨鑫 on 15/6/24.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNAddCareRecordSheetsPopView.h"
#import "WCButton.h"
//
#import "Macros.h"

@interface WCNAddCareRecordSheetsPopView ()

@property (nonatomic) CGPoint point;

@end

@implementation WCNAddCareRecordSheetsPopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        [self loadView];
    }
    return self;
}

- (void)loadView
{
    CGRect bounds = self.bounds;
    
    CGRect frame = CGRectMake(0, 5, bounds.size.width, 40);
    WCButton *btn1 = [[WCButton alloc] initWithFrame:frame];
    btn1.tag = 0;
    btn1.imageFrame = CGRectMake(6, 15, 10, 10);
    btn1.titleFrame = CGRectMake(25, 0, bounds.size.width-25, 40);
    btn1.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [btn1 setImage:[UIImage imageNamed:@"CaseCell_BlueHeader"] forState:UIControlStateNormal];
    [btn1 setTitle:@"新添伤口" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(addRecord:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn1];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(22, 45, 102, kOnePX)];
    view.backgroundColor = kBorderColor;
    [self addSubview:view];
    
    frame.origin.y += 40;
    WCButton *btn2 = [[WCButton alloc] initWithFrame:frame];
    btn2.tag = 1;
    btn2.imageFrame = CGRectMake(6, 15, 10, 10);
    btn2.titleFrame = CGRectMake(25, 0, bounds.size.width-25, 40);
    btn2.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [btn2 setImage:[UIImage imageNamed:@"CaseCell_GreenHeader"] forState:UIControlStateNormal];
    [btn2 setTitle:@"伤口护理记录" forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(addRecord:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn2];
}

- (void)addRecord:(WCButton *)btn
{
    self.itemclick(btn.tag);
}

- (void)show:(void(^)(void))complete
{
    self.alpha = .0;
    [UIView animateWithDuration:.25 animations:^{
        self.alpha = 1.0;
    } completion:^(BOOL finished){
        complete?complete():nil;
    }];
}

- (void)hide:(void(^)(void))complete
{
    [UIView animateWithDuration:.25 animations:^{
        self.alpha = .0;
    } completion:^(BOOL finished){
        [self removeFromSuperview];
        complete?complete():nil;
    }];
}

- (void)setPoint:(CGPoint)point
{
    _point = point;
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    UIBezierPath *path = [[UIBezierPath alloc] init];
    
    CGPoint start = CGPointMake(2, 5);
    [path moveToPoint:start];
    
    CGPoint end = CGPointMake(self.point.x-5, 5);
    [path addLineToPoint:end];
    
    end = CGPointMake(self.point.x, 0);
    [path addLineToPoint:end];
    
    end = CGPointMake(self.point.x+5, 5);
    [path addLineToPoint:end];
    
    end = CGPointMake(rect.size.width-2, 5);
    [path addLineToPoint:end];
    
    end.y += 2;
    [path addArcWithCenter:end radius:2 startAngle:1.5*M_PI endAngle:0*M_PI clockwise:YES];
    
    end = CGPointMake(rect.size.width, rect.size.height-2);
    [path addLineToPoint:end];
    
    end.x -= 2;
    [path addArcWithCenter:end radius:2 startAngle:0*M_PI endAngle:0.5*M_PI clockwise:YES];
    
    end = CGPointMake(2, rect.size.height);
    [path addLineToPoint:end];
    
    end.y -= 2;
    [path addArcWithCenter:end radius:2 startAngle:0.5*M_PI endAngle:1.0*M_PI clockwise:YES];
    
    end = CGPointMake(0, 7);
    [path addLineToPoint:end];
    
    end.x += 2;
    [path addArcWithCenter:end radius:2 startAngle:1.0*M_PI endAngle:1.5*M_PI clockwise:YES];
    
    [HexRGBAlpha(0x000000, .8) setFill];
    [path fill];
}

@end
